


let R = require('ramda');


// let Bacon = require('baconjs');
// const events = require('events');
//
// const eventEmitter = new events.EventEmitter();
// Bacon.fromEvent(eventEmitter,'some event')
//     .onValue((data)=>{
//         console.log(data);
//     });
//
// eventEmitter.emit('some event','hello world!');


const match = R.curry(function(what,str){
    return str.match(what);
});

const replace = R.curry(function (what,replacement,str) {
    return str.replace(what,replacement);
});

const filter = R.curry(function (f,ary) {
   return ary.filter(f);
});

const map = R.curry(function (f,ary) {
    return ary.map(f);
});
//
// console.log(match(/o/g,'hello world!'));
// console.log(replace(/o/g)('XX')('hello world!'));


// const even = filter((value)=>{
//     return value % 2 === 0;
// });
//
// const odd = map(function (value) {
//     if(value % 2 === 1){
//         return value
//     }
//     return undefined;
// });
//
// console.log(even([1,2,3,4,5,6]));
// console.log(odd([1,2,3,4,5,6]));



const trace = R.curry(function (tag,x) {
    console.log(tag,x);
    return x;
});

const isEven = function (x) {
    return x % 2 === 0;
};

const even = filter(isEven);

const square = function (x) {
    return x * x;
};


// const n2s = R.compose(R.map(square),even);
// console.log(n2s([1,2,3,4,5]));
//
//
// const toUpper = x => x.toUpperCase();
// const exam = x => x + '!';
//
// const toex = R.compose(exam,trace('LOG:'),toUpper);
// console.log(toex('hello world'));


//   (b->b)->b->[b]->b
const reduce = R.curry(function (f,x,xs) {
    return xs.reduce(f,x);
});
const sum = function(pre,cur){
   return pre + cur;
};

console.log(reduce(sum,10)([1,2,3,4,5]));
